﻿/*
  Copyright © Alexander G. Bykin, Russia 2009-2010
  This source is subject to the Microsoft Public License (Ms-PL).
  Please see http://go.microsoft.com/fwlink/?LinkID=131993 for details.
  All other rights reserved.
*/

namespace System.Windows.Controls
{
    using System.Collections.Generic;
    using System.Linq;

    public sealed class FilterOperatorWithFieldTypes
    {
        public List<FilterOperatorWithFieldType> FilterOperatorWithFieldTypeList
        {
            get
            {
                if (this.filterOperatorWithFieldTypeList == null)
                {
                    this.filterOperatorWithFieldTypeList = new List<FilterOperatorWithFieldType>();
                    this.filterOperatorWithFieldTypeList.Add(
                        new FilterOperatorWithFieldType()
                        {
                            FilterOperator = FilterOperator.Contains,
                            TypeList = new List<Type>()
                            {
                                typeof(string)
                            }
                        });

                    this.FilterOperatorWithFieldTypeList.Add(
                        new FilterOperatorWithFieldType()
                        {
                            FilterOperator = FilterOperator.EndsWith,
                            TypeList = new List<Type>()
                            {
                                typeof(string)
                            }
                        });

                    this.FilterOperatorWithFieldTypeList.Add(
                        new FilterOperatorWithFieldType()
                        {
                            FilterOperator = FilterOperator.IsContainedIn,
                            TypeList = new List<Type>()
                            {
                                typeof(string)
                            }
                        });

                    this.FilterOperatorWithFieldTypeList.Add(
                        new FilterOperatorWithFieldType()
                        {
                            FilterOperator = FilterOperator.IsEqualTo,
                            TypeList = new List<Type>()
                            {
                                typeof(string),
                                typeof(bool),
                                typeof(int),
                                typeof(decimal),
                                typeof(byte),
                                typeof(DateTime)
                            }
                        });

                    this.FilterOperatorWithFieldTypeList.Add(
                        new FilterOperatorWithFieldType()
                        {
                            FilterOperator = FilterOperator.IsGreaterThan,
                            TypeList = new List<Type>()
                            {
                                typeof(string),
                                typeof(int),
                                typeof(decimal),
                                typeof(byte)
                            }
                        });

                    this.FilterOperatorWithFieldTypeList.Add(
                        new FilterOperatorWithFieldType()
                        {
                            FilterOperator = FilterOperator.IsGreaterThanOrEqualTo,
                            TypeList = new List<Type>()
                            {
                                typeof(string),
                                typeof(int),
                                typeof(decimal),
                                typeof(byte)
                            }
                        });

                    this.FilterOperatorWithFieldTypeList.Add(
                        new FilterOperatorWithFieldType()
                        {
                            FilterOperator = FilterOperator.IsLessThan,
                            TypeList = new List<Type>()
                            {
                                typeof(string),
                                typeof(int),
                                typeof(decimal),
                                typeof(byte)
                            }
                        });

                    this.FilterOperatorWithFieldTypeList.Add(
                        new FilterOperatorWithFieldType()
                        {
                            FilterOperator = FilterOperator.IsLessThanOrEqualTo,
                            TypeList = new List<Type>()
                            {
                                typeof(string),
                                typeof(int),
                                typeof(decimal),
                                typeof(byte)
                            }
                        });

                    this.FilterOperatorWithFieldTypeList.Add(
                        new FilterOperatorWithFieldType()
                        {
                            FilterOperator = FilterOperator.IsNotEqualTo,
                            TypeList = new List<Type>()
                            {
                                typeof(string),
                                typeof(bool),
                                typeof(int),
                                typeof(decimal),
                                typeof(byte),
                                typeof(DateTime)
                            }
                        });

                    this.FilterOperatorWithFieldTypeList.Add(
                        new FilterOperatorWithFieldType()
                        {
                            FilterOperator = FilterOperator.StartsWith,
                            TypeList = new List<Type>()
                            {
                                typeof(string)
                            }
                        });
                }

                return this.filterOperatorWithFieldTypeList;
            }
        }

        private List<FilterOperatorWithFieldType> filterOperatorWithFieldTypeList { get; set; }

        public List<FilterOperator> GetFilterOperatorListByFieldType(Type type)
        {
            List<FilterOperator> result = new List<FilterOperator>();
            foreach (var item in this.FilterOperatorWithFieldTypeList.Where(r => r.TypeList.Contains(type)))
            {
                result.Add(item.FilterOperator);
            }
            return result;
        }
    }
}
